//
//  UserDefaultsExtension.swift
//  test_2
//
//  Created by 王鑫 on 2020/12/30.
//

import Foundation
extension UserDefaults {
    //登录信息
    enum LoginKeys: String {
        case token
        case userId
    }
    
    //账户信息
    enum AccountKeys: String {
        case userName
        case age
    }
    
    
    static func set(value: String, forKey key: LoginKeys) {
        let key = key.rawValue
        UserDefaults.standard.set(value, forKey: key)
    }

    static func string(forKey key: LoginKeys) -> String? {
        let key = key.rawValue
        return UserDefaults.standard.string(forKey: key)
    }
    
    static func set(value: String, forKey key: AccountKeys) {
        let key = key.rawValue
        UserDefaults.standard.set(value, forKey: key)
    }

    static func string(forKey key: AccountKeys) -> String? {
        let key = key.rawValue
        return UserDefaults.standard.string(forKey: key)
    }
}
